import requests
from lxml import etree
# pip install lxml
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
}
# 发起请求
response = requests.get(url="https://movie.douban.com/top250", headers=headers)

print(response.status_code)

# 获取网站的源代码
text = response.text

# 解析源代码
html = etree.HTML(text)
# 查找到所有电影
items = html.xpath("//div[@class='item']")

# 循环解析每一个电影
for item in items:
    name = item.xpath("div[@class='info']/div[1]/a/span[1]/text()")[0]
    desc = item.xpath("div[@class='info']/div[2]/p/text()")[0].strip()
    print(desc)


